package test;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.LocalFileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.SequenceFile.Writer;
import org.apache.hadoop.io.Text;

import com.tonghui.dm.io.ArrayListWritable;


/**
 * <p>为Job准备数据</p>
 * @author running
 *
 */
public class PrepareDataForJob {

	/**
	 * <p>查询商品�?��分类，并写入HDFS</p>
	 * @param userKey
	 * @param savePath
	 * @throws IOException 
	 */
	public static void itemKeyAndSellerCat(String userKey, String savePath) throws IOException{
		Path subdir = new Path("e:/test", "new");
		
		Configuration conf = new Configuration();
		LocalFileSystem fs = FileSystem.getLocal(conf);
	    
		SequenceFile.Writer writer = SequenceFile.createWriter(fs, conf, subdir, Text.class, ArrayListWritable.class);
		
		Text key = new Text("a");
		ArrayListWritable arrayListWritable1 = new ArrayListWritable();
		arrayListWritable1.add("23423");
		arrayListWritable1.add("sdfb");
		writer.append(key, arrayListWritable1);
		ArrayListWritable arrayListWritable2 = new ArrayListWritable();
		arrayListWritable2.add("23ss423");
		arrayListWritable2.add("sdfb");
		writer.append(key, arrayListWritable2);
		IOUtils.closeStream(writer);
	}
	
	public static void readItemKeyAndSellerCat() throws IOException{
		Path subdir = new Path("e:/test","new");
		Configuration conf = new Configuration();
		LocalFileSystem fs = FileSystem.getLocal(conf);
		SequenceFile.Reader reader = new SequenceFile.Reader(fs, subdir, conf);
		Text key = new Text();
		
		ArrayListWritable value1 = new ArrayListWritable();
		reader.next(key, value1);
		System.out.println(value1.toString());
		
		value1 = new ArrayListWritable();
		reader.next(key, value1);
		System.out.println(value1.toString());
		IOUtils.closeStream(reader);
	}
	
	
	
	public static void main(String[] args) throws IOException {
		Configuration conf = new Configuration();
		System.out.println(conf);
	}
	
}
